package com.chinaums.xm.wechat.controller;

import java.io.UnsupportedEncodingException;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.chinaums.xm.wechat.service.wechat.AccountService;

import io.swagger.annotations.ApiOperation;

/**
 * 二维码相关服务
 * @author chenjf
 *
 */
@RequestMapping("/wechat")
@RestController
public class AccountController {

//	private static final Logger logger = LoggerFactory.getLogger(WeixinController.class);
	
	@Resource
	private AccountService accountService;
	
	/**
	 * {"ticket":"gQGn8DwAAAAAAAAAAS5odHRwOi8vd2VpeGluLnFxLmNvbS9xLzAyQ2o2d2g5eUJjNzAxQ3BxdHhvMTkAAgQZIJRYAwSAOgkA",
	 * "expire_seconds":604800,"url":"http:\/\/weixin.qq.com\/q\/02Cj6wh9yBc701Cpqtxo19"}
	 */
	@ApiOperation(value = "创建临时二维码", notes = "创建临时二维码")
	@RequestMapping(value = { "/createTempTicket" }, method = RequestMethod.GET)
	public void createTempTicket(){
		accountService.createTempTicket("604800", "QR_SCENE");
	}
	
	@ApiOperation(value = "创建永久二维码", notes = "创建永久二维码")
	@RequestMapping(value = { "/createForeverTicket" }, method = RequestMethod.GET)
	public void createForeverTicket(){
		accountService.createForeverTicket("QR_LIMIT_SCENE");
	}
	
	@ApiOperation(value = "下载二维码", notes = "下载二维码")
	@RequestMapping(value = { "/getTempTicket" }, method = RequestMethod.GET)
	public void getTempTicket(){
		try {
			accountService.getTempTicket("gQEC8jwAAAAAAAAAAS5odHRwOi8vd2VpeGluLnFxLmNvbS9xLzAyU0xrcmg2eUJjNzAxMDAwME0wMy0AAgSmKJRYAwQAAAAA");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
	}
	
	@ApiOperation(value = "下载二维码", notes = "下载二维码")
	@RequestMapping(value = { "/getForeverTicket" }, method = RequestMethod.GET)
	public void getForeverTicket(){
		try {
			accountService.getForeverTicket("gQEC8jwAAAAAAAAAAS5odHRwOi8vd2VpeGluLnFxLmNvbS9xLzAyU0xrcmg2eUJjNzAxMDAwME0wMy0AAgSmKJRYAwQAAAAA");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
	}
}
